package cc.geguol.statement;

import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by 13687 on 2017/2/11.
 * DML 插入 删除 修改表
 */
public class DMLDemo {
	private String uri="jdbc:mysql://localhost:3306/demo";
	private String user = "root";
	private String pwd = "root";
	private Connection conn;
	private Statement stmt;//连接

	/**
	 * @throws ClassNotFoundException
	 * dml
	 */
	@Test
	public void test1() throws ClassNotFoundException {
		//1.驱动注册程序
		Class.forName("com.mysql.jdbc.Driver");

		try{
			//2.获取连接对象
			conn = DriverManager.getConnection(uri, user, pwd);

			//3.创建Statement
			stmt = conn.createStatement();

			String sql="insert into student(name,gender) values('weiwei2','女')";

			int count  =  stmt.executeUpdate(sql);
		}catch(Exception e){
			e.printStackTrace();
			throw new RuntimeException(e);
		}finally {
			if (stmt!=null){
				try {
					stmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}

			if (conn!=null){
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}



	}

}
